package com.wangxl.rabbitmqdemo.consumer;

import com.wangxl.rabbitmqdemo.dto.BasicMessageInput;
import com.wangxl.rabbitmqdemo.util.ObjectSerializeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.UnsupportedEncodingException;

/**
 * 消息消费者
 * @Author: wangxl
 * @Date: 2019/3/23 13:44
 */
@Configuration
@Slf4j
public class BusinessConsumerConfig {

    /**
     * 配置业务--短信消费者
     * @param message
     */
    @RabbitListener(queues = "messageQueue")
    public void sendBusinessMessage(Message message) throws UnsupportedEncodingException {
        byte[] messageBody = message.getBody();
        log.info("get message content from messageQueue---{}",new String(messageBody,"UTF-8"));
    }

    /**
     * 配置业务--邮件消费者
     * @param message
     */
    @RabbitListener(queues = "emailQueue")
    public void sendBusinessEmail(Message message) throws UnsupportedEncodingException {
        log.info("sendBusinessEmail get email content from emailQueue---------------------------------------------------");
//        byte[] messageBody = message.getBody();
//
//        BasicMessageInput<String> obj = (BasicMessageInput<String>) ObjectSerializeUtil.unserialize(messageBody);
//        log.info("get email content from emailQueue---{}",obj.toString());
    }

    /**
     * 配置业务--邮件消费者
     * @param message
     */
    @RabbitListener(queues = "emailQueue")
    public void sendBusinessEmail1(Message message) throws UnsupportedEncodingException {
        log.info("sendBusinessEmail1111 get email content from emailQueue---------------------------------------------------");
//        byte[] messageBody = message.getBody();
//
//        BasicMessageInput<String> obj = (BasicMessageInput<String>) ObjectSerializeUtil.unserialize(messageBody);
//        log.info("get email content from emailQueue---{}",obj.toString());
    }

    /**
     * 配置业务--邮件消费者
     * @param message
     */
    @RabbitListener(queues = "emailQueue")
    public void sendBusinessEmail2(Message message) throws UnsupportedEncodingException {
        log.info("sendBusinessEmail2222 get email content from emailQueue---------------------------------------------------");
        //byte[] messageBody = message.getBody();

        //BasicMessageInput<String> obj = (BasicMessageInput<String>) ObjectSerializeUtil.unserialize(messageBody);
        //log.info("get email content from emailQueue---{}",obj.toString());
    }

}
